function showDetails(id) {
    alert(`显示植物${id}的详细信息`);
    // 这里可以添加更多交互逻辑
}

// 滚动效果
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
    anchor.addEventListener('click', function (e) {
        e.preventDefault();
        document.querySelector(this.getAttribute('href')).scrollIntoView({
            behavior: 'smooth'
        });
    });
});

// 数字动画效果
function animateNumber(element, target, duration = 2000) {
    let start = 0;
    const increment = target / (duration / 16);
    const timer = setInterval(() => {
        start += increment;
        if (start >= target) {
            clearInterval(timer);
            start = target;
        }
        element.textContent = Math.floor(start) + (element.dataset.suffix || '');
    }, 16);
}

// 监听元素进入视口
const observer = new IntersectionObserver((entries) => {
    entries.forEach(entry => {
        if (entry.isIntersecting) {
            const element = entry.target;
            const value = parseInt(element.dataset.value);
            if (value) {
                animateNumber(element, value);
            }
            observer.unobserve(element);
        }
    });
}, {
    threshold: 0.5
});

// 添加监听
document.addEventListener('DOMContentLoaded', () => {
    // 为所有带有 data-value 属性的数字添加动画
    document.querySelectorAll('.stat-number[data-value], .detail-number[data-value]').forEach(el => {
        observer.observe(el);
    });

    // 为进度条添加动画
    document.querySelectorAll('.progress').forEach(progress => {
        const width = progress.style.width;
        progress.style.width = '0';
        setTimeout(() => {
            progress.style.width = width;
        }, 100);
    });
}); 